package baptizeattribute.dao;

import baptizeattribute.pojo.Attribute;
import baptizeattribute.resource.PathConfiguration;
import baptizeattribute.utils.IOUtil;

import java.util.*;

public class AttributeDao {
    String path = PathConfiguration.ConfiguerYml;

    /**
     * 获得所有属性的集合
     * @return
     */
    public List<Attribute> getAttributeList() {
        List<Attribute> attributeList = new ArrayList<>();
        List<String> stringList = new ArrayList<>();
        Map<String,String> map;
        Set<String> ketlist = IOUtil.getKeys(path, false);
        for (String key : ketlist) {
            if (!key.equals("DetectionTitle") && !key.equals("Info")&& !key.equals("InvTitle")
            && !key.equals("Info2")) {
                map = new HashMap<>();
                Attribute attribute = new Attribute();
                attribute.setId(key);
                attribute.setTitle(IOUtil.getString(path, key + ".Title"));
                attribute.setNumBer(IOUtil.getInt(path, key + ".Number"));
                attribute.setRandom(IOUtil.getString(path,key+".Random"));
                stringList=(IOUtil.getList(path, key + ".AttributeList"));
                for (String s : stringList) {
                    String[] split = s.split("\\|");
                    map.put(split[0],split[1]);
                }
                attribute.setAttributelist(map);
                attributeList.add(attribute);
            }
        }
        return attributeList;
    }
}
